"""
Copyright (c) 2022 Huawei Technologies Co.,Ltd.

openGauss is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:

          http://license.coscl.org.cn/MulanPSL2

THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
"""
"""
Case Type   : 功能-功能测试
Case Name   : 管理员创建新角色
Create At   : 2023/5/19
Owner       : n@ningyali
Description :
    1. 点击安全中心-角色与权限
    2. 点击“添加角色”
    3. 选择一些菜单赋予权限
    4. 点击确定【结果1】
Expect      :
    1.【结果1】角色成功创建
History     :
"""
import os
import time
import unittest

from selenium.webdriver.common.by import By

from openGaussMigrate.common.base import Base
from openGaussMigrate.common.com_log import ComLog
from openGaussMigrate.common.com_node import Macro
from openGaussMigrate.common.com_unit_action import ComUnitAction


class Install0015(unittest.TestCase):
    def setUp(self):
        self.log = ComLog(self.__class__.__name__)
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        web = Macro('WEB_INFO')
        self.driver = ComUnitAction(web.info['driver_path'], web.info['url'])
        self.driver.open()
        self.driver.login(web.info['user'], web.info['passwd'])
        self.log.info('setup run finished')
        self.role_name = 'install0015'

    @Base.retry(max_n=1)
    @Base.save_img_when_err(cls_name='Install0015')
    def test_case1(self):
        """管理员创建新角色"""
        self.driver.create_role(self.role_name, '日志中心,智能运维')

    def tearDown(self):
        try:
            self.driver.drop_role(self.role_name)
        except Exception as e:
            self.log.error(str(e))
        finally:
            self.driver.close()
            self.log.info('teardown run finished')
